/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.matrimonybeans;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;

/**
 *
 * @author 4410s
 */
@Stateless
public class ChangePassowrd_Candidate implements ChangePassowrd_CandidateLocal {

    Connection conn;
    ResultSet rs = null;

    @Override
    public ResultSet Select_Candidate_Password(String username) {
        try {
            ConnectDB conDB = new ConnectDB();
            conn = conDB.getConnection();
            String strSql = "SELECT * from Candidate where username=? ";
            PreparedStatement pstmt = conn.prepareStatement(strSql);
            pstmt.setString(1, username);
            
            rs = pstmt.executeQuery();

        } catch (SQLException ex) {
            Logger.getLogger(ChangePassowrd_Candidate.class.getName()).log(Level.SEVERE, null, ex);
        }
        return rs;
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
   
    boolean flag=false;
    @Override
    public Boolean Change_password_candidate(String password, String username) {
        try {
            ConnectDB conDB = new ConnectDB();
            conn = conDB.getConnection();
            String strSql_update = "Update Candidate set password=? where username=? ";
            PreparedStatement pstmt_update = conn.prepareStatement(strSql_update);
            
            pstmt_update.setString(1, password);
            pstmt_update.setString(2,username);
            int count=0;
            count= pstmt_update.executeUpdate();
            if (count>0) {
                flag=true;
            }else
            {
                flag=false;
            }
           
        } catch (SQLException ex) {
            Logger.getLogger(ChangePassowrd_Candidate.class.getName()).log(Level.SEVERE, null, ex);
        }
         return flag;
    }
}
